from strategy_mode import dataLoader, str_cal, Trading, TradingRules

# 上涨模式
def UpMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


# 下跌模式
def DownMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


def RoundMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


def Main(
    df_d,
    df_day,
    df_day_1,
    mode="BUY/SELL",
    line_Pares=5,
    tradePersent=1,
    day_lists=[],
    day=0,
    statsdic={},
    count_in=1,
    trade_cuts=1,
):

    preTYPES = statsdic["TYPES"]
    down_gap = 2 / 12
    up_gap = 4 / 12
    # 下跌模式

    if (
        df_day["close_sort"] < -down_gap
        and df_day["open_sort"] < -down_gap
        and df_day["high_sort"] < -down_gap
        and df_day["low_sort"] < -down_gap
    ):
        statsdic["TYPES"] = "LOW"
        if statsdic["Share"] > 0 and (
            round(df_day["close_by%Boll_sum"], 2)
            == round(df_day["open_by%Boll_sum"], 2)
            == round(df_day["low_by%Boll_sum"], 2)
            == round(df_day["high_by%Boll_sum"], 2)
            and round(df_day["close_by%Boll_sum"], 2) >= 0.3
        ):
            tradePersent = 1
            mode = "SELL"
        elif (
            round(df_day["close_by%Boll_sum"], 2)
            == round(df_day["open_by%Boll_sum"], 2)
            == round(df_day["low_by%Boll_sum"], 2)
            == round(df_day["high_by%Boll_sum"], 2)
            and round(df_day["close_by%Boll_sum"], 2) <= -0.9
            and TradingRules.Main_compare_or(df_day, -1, num=0.5, mode="DOWN")
        ):
            mode = "BUY"
            tradePersent = 0.2

    elif (
        df_day["close_sort"] > up_gap
        and df_day["open_sort"] > up_gap
        and df_day["high_sort"] > up_gap
        and df_day["low_sort"] > up_gap
    ):
        statsdic["TYPES"] = "HIGH"
        if statsdic["Share"] > 0 and (
            round(df_day["close_by%Boll_sum"], 2)
            == round(df_day["open_by%Boll_sum"], 2)
            == round(df_day["low_by%Boll_sum"], 2)
            == round(df_day["high_by%Boll_sum"], 2)
            and round(df_day["close_by%Boll_sum"], 2) >= 0.6
            and TradingRules.Main_compare_or(df_day, 1, num=0.5, mode="UP")
        ):
            tradePersent = 0.2
            mode = "SELL"
        elif (
            round(df_day["close_by%Boll_sum"], 2)
            == round(df_day["open_by%Boll_sum"], 2)
            == round(df_day["low_by%Boll_sum"], 2)
            == round(df_day["high_by%Boll_sum"], 2)
            and round(df_day["close_by%Boll_sum"], 2) <= 0.5
            and TradingRules.Main_compare_or(df_day, -1, num=0, mode="DOWN")
        ):
            mode = "BUY"
            tradePersent = 1

    else:  # 横盘模式
        statsdic["TYPES"] = "ROUND"
        if statsdic["Share"] > 0 and (
            round(df_day["close_by%Boll_sum"], 2)
            == round(df_day["open_by%Boll_sum"], 2)
            == round(df_day["low_by%Boll_sum"], 2)
            == round(df_day["high_by%Boll_sum"], 2)
            and round(df_day["close_by%Boll_sum"], 2) >= 0.4
            and TradingRules.Main_compare_or(df_day, 1, num=0.4, mode="UP")
        ):
            tradePersent = 0.5
            mode = "SELL"
        elif (
            round(df_day["close_by%Boll_sum"], 2)
            == round(df_day["open_by%Boll_sum"], 2)
            == round(df_day["low_by%Boll_sum"], 2)
            == round(df_day["high_by%Boll_sum"], 2)
            and round(df_day["close_by%Boll_sum"], 2) <= -0.5
            and TradingRules.Main_compare_or(df_day, -1, num=0.4, mode="DOWN")
        ):
            mode = "BUY"
            tradePersent = 0.5

        # mode, tradePersent = RoundMode(
        #     df_d, df_day, preTYPES, mode, tradePersent, day_lists, statsdic, count_in
        # )

    return mode, tradePersent * trade_cuts